/**
*   get CGI variables test servlet
*   4/6/2012
*/

package org.buptjunjun.servlet;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;

public class ShowCGIVariables extends HttpServlet
{
    public void doGet(HttpServletRequest request,
                  	 HttpServletResponse response) 
					 throws IOException ,ServletException
	{
		response.setContentType("text/html");
		PrintWriter out = response.getWriter();
		String[][] variables =
		{ 
			{ "AUTH_TYPE", request.getAuthType() },
			{ "CONTENT_LENGTH", String.valueOf(request.getContentLength()) },
			{ "CONTENT_TYPE", request.getContentType() },
			{ "DOCUMENT_ROOT", getServletContext().getRealPath("/") },
			{ "PATH_INFO", request.getPathInfo() },
			{ "PATH_TRANSLATED", request.getPathTranslated() },
			{ "QUERY_STRING", request.getQueryString() },
			{ "REMOTE_ADDR", request.getRemoteAddr() },
			{ "REMOTE_HOST", request.getRemoteHost() },
			{ "REMOTE_USER", request.getRemoteUser() },
			{ "REQUEST_METHOD", request.getMethod() },
			{ "SCRIPT_NAME", request.getServletPath() },
			{ "SERVER_NAME", request.getServerName() },
			{ "SERVER_PORT", String.valueOf(request.getServerPort()) },
			{ "SERVER_PROTOCOL", request.getProtocol() },
			{ "SERVER_SOFTWARE", getServletContext().getServerInfo() }
		};
	
	
		for(int i = 0; i < variables.length; i++)
		{
			String name = variables[i][0];
			String value = variables[i][1];
			out.println(name + "  :  " + value +"<BR>");
		}
	}
    public void doPost(HttpServletRequest request,
	              HttpServletResponse response)
				  throws IOException, ServletException
	{
	    doGet(request,response);
	}

}